import 'package:flutter_module/core/app_env.dart';
import 'package:flutter_module/core/flutter_bridge.dart';

/// Create by kyluzoi
/// Date: 2021-07-30
///
/// Description: 请求基类定义

enum RequestMethod { GET, POST }

abstract class BaseRequest {
  Future<String> url() async {
    EnvConfig config =
        AppEnv.app2Env ?? await FlutterPlatformBridge.getInstance().getHost();
    return config.apiBaseURL;
  }

  RequestMethod requestMethod();

  String path();

  /// 定义是否需要登录权限
  bool needLogin();

  Map<String, String> queryParams = Map();
  Map<String, dynamic> bodyParams = Map();

  bool isJson() {
    return true; // body 是否是 json 格式
  }

  Map<String, String> addQurey(String k, Object v) {
    queryParams[k] = v.toString();
    return queryParams;
  }

  Map<String, dynamic> add(String k, dynamic v) {
    bodyParams[k] = v;
    return bodyParams;
  }
}
